/**
 * Copyright (C) 2018-2022
 * All rights reserved, Designed By www.dynread.com
 * 注意：
 * 本软件为www.dynread.com开发研制，项目使用请保留此说明
 */
package com.dynread.mall.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.dynread.common.core.domain.BaseModel;
import com.dynread.mall.config.CommonConstants;
import com.dynread.mall.enums.OrderInfoEnum;
import com.dynread.weixin.entity.WxUser;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 商城订单
 *
 * @author drinvay
 * @date 2022/5/6 17:29
 */
@Data
@TableName("order_info")
@EqualsAndHashCode(callSuper = true)
@ApiModel(description = "商城订单")
public class OrderInfo extends BaseModel {
    private static final long serialVersionUID = 1L;

    /**
     * 用户ID
     */
    @ApiModelProperty(value = "用户ID")
    private String userId;

    /**
     * 订单号
     */
    @ApiModelProperty(value = "订单号")
    private String orderNo;

    /**
     * 支付方式（1货到付款 2在线支付）
     */
    @ApiModelProperty(value = "支付方式（1货到付款 2在线支付）")
    private String paymentWay;

    /**
     * 是否支付（0未支付 1已支付）
     */
    @ApiModelProperty(value = "是否支付（0未支付 1已支付）")
    private String isPay;

    /**
     * 订单名
     */
    @ApiModelProperty(value = "订单名")
    private String name;

    /**
     * 订单状态（1待发货 2待收货 3确认收货/已完成 5已关闭）
     */
    @ApiModelProperty(value = "订单状态（1待发货 2待收货 3确认收货/已完成 5已关闭）")
    private String status;

    /**
     * 运费金额
     */
    @ApiModelProperty(value = "运费金额")
    private BigDecimal freightPrice;

    /**
     * 销售金额
     */
    @ApiModelProperty(value = "销售金额")
    private BigDecimal salesPrice;

    /**
     * 支付金额（销售金额+运费金额-积分抵扣金额-电子券抵扣金额）
     */
    @ApiModelProperty(value = "支付金额（销售金额+运费金额-积分抵扣金额-电子券抵扣金额）")
    private BigDecimal paymentPrice;

    /**
     * 付款时间
     */
    @ApiModelProperty(value = "付款时间")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime paymentTime;

    /**
     * 发货时间
     */
    @ApiModelProperty(value = "发货时间")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime deliveryTime;

    /**
     * 收货时间
     */
    @ApiModelProperty(value = "收货时间")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime receiverTime;

    /**
     * 成交时间
     */
    @ApiModelProperty(value = "成交时间")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime closingTime;

    /**
     * 买家留言
     */
    @ApiModelProperty(value = "买家留言")
    private String userMessage;

    /**
     * 支付交易ID
     */
    @ApiModelProperty(value = "支付交易ID")
    private String transactionId;

    /**
     * 物流ID
     */
    @ApiModelProperty(value = "物流ID")
    private String logisticsId;

    /**
     * 备注
     */
    @ApiModelProperty(value = "备注")
    private String remark;

    /**
     * 订单详情
     */
    @TableField(exist = false)
    private List<OrderItem> listOrderItem;

    /**
     * 订单状态过期时间
     */
    @TableField(exist = false)
    private Long outTime;

    /**
     * 状态0、待付款 1、待发货 2、待收货 3、已完成 4、已关闭
     */
    @TableField(exist = false)
    private String statusDesc;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(exist = false)
    private LocalDateTime beginTime;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(exist = false)
    private LocalDateTime endTime;

    /**
     * 订单物流
     */
    @TableField(exist = false)
    private OrderLogistics orderLogistics;

    /**
     * 物流商家
     */
    @TableField(exist = false)
    private String logistics;

    /**
     * 用户信息
     */
    @TableField(exist = false)
    private WxUser userInfo;

    /**
     * 物流单号
     */
    @TableField(exist = false)
    private String logisticsNo;

    public String getStatusDesc() {
        if (CommonConstants.NO.equals(this.isPay) && this.status == null) {
            return "待付款";
        }
        if (this.status == null) {
            return null;
        }
        return OrderInfoEnum.valueOf(OrderInfoEnum.STATUS_PREFIX + "_" + this.status).getDesc();
    }

	@TableField(exist = false)
	private String createBy;
	@TableField(exist = false)
	private String updateBy;
}
